<!DOCTYPE html>
<html lang=zh>
<head>
    <meta charset="utf-8">
    
    <title>第四十四章： 基于SpringBoot &amp; AOP完成统一资源自动查询映射 | 恒宇少年De成长之路</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="description" content="本章内容比较偏向系统设计方面，简单的封装就可以应用到系统中使用，从而提高我们的编码效率以及代码的可读性。统一资源在系统内是不可避免的模块，资源分类也有很多种，比较常见如：图片资源、文本资源、视频资源等，那么资源统一处理的好处是什么呢？大家有可能会有疑问，我把资源存放到业务表内岂不更好吗？这样查询起来也方便，并不需要关联资源信息表！当然设计不分好坏，只有更适合、更简单！接下来带着疑问进入本章的内容。">
<meta name="keywords" content="SpringBoot">
<meta property="og:type" content="article">
<meta property="og:title" content="第四十四章： 基于SpringBoot &amp; AOP完成统一资源自动查询映射">
<meta property="og:url" content="http://blog.yuqiyu.com/spring-boot-chapter-44/index.html">
<meta property="og:site_name" content="恒宇少年De成长之路">
<meta property="og:description" content="本章内容比较偏向系统设计方面，简单的封装就可以应用到系统中使用，从而提高我们的编码效率以及代码的可读性。统一资源在系统内是不可避免的模块，资源分类也有很多种，比较常见如：图片资源、文本资源、视频资源等，那么资源统一处理的好处是什么呢？大家有可能会有疑问，我把资源存放到业务表内岂不更好吗？这样查询起来也方便，并不需要关联资源信息表！当然设计不分好坏，只有更适合、更简单！接下来带着疑问进入本章的内容。">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-d80b777ca38632ba.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:updated_time" content="2018-01-23T15:56:50.150Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="第四十四章： 基于SpringBoot &amp; AOP完成统一资源自动查询映射">
<meta name="twitter:description" content="本章内容比较偏向系统设计方面，简单的封装就可以应用到系统中使用，从而提高我们的编码效率以及代码的可读性。统一资源在系统内是不可避免的模块，资源分类也有很多种，比较常见如：图片资源、文本资源、视频资源等，那么资源统一处理的好处是什么呢？大家有可能会有疑问，我把资源存放到业务表内岂不更好吗？这样查询起来也方便，并不需要关联资源信息表！当然设计不分好坏，只有更适合、更简单！接下来带着疑问进入本章的内容。">
<meta name="twitter:image" content="http://upload-images.jianshu.io/upload_images/4461954-d80b777ca38632ba.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
    

    
        <link rel="alternate" href="/" title="恒宇少年De成长之路" type="application/atom+xml" />
    

    

    <link rel="stylesheet" href="/libs/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/libs/open-sans/styles.css">
    <link rel="stylesheet" href="/libs/source-code-pro/styles.css">

    <link rel="stylesheet" href="/css/style.css">

    <script src="/libs/jquery/2.1.3/jquery.min.js"></script>
    
    
        <link rel="stylesheet" href="/libs/lightgallery/css/lightgallery.min.css">
    
    
        <link rel="stylesheet" href="/libs/justified-gallery/justifiedGallery.min.css">
    
    
    
    


</head>

<body>
    <div id="container">
        <header id="header">
    <div id="header-main" class="header-inner">
        <div class="outer">
            <a href="/" id="logo">
                <i class="logo"></i>
                <span class="site-title">恒宇少年De成长之路</span>
            </a>
            <nav id="main-nav">
                
                    <a class="main-nav-link" href="/.">首页</a>
                
                    <a class="main-nav-link" href="/archives">时间轴</a>
                
                    <a class="main-nav-link" href="/categories">文章专题</a>
                
                    <a class="main-nav-link" href="/tags">标签云</a>
                
                    <a class="main-nav-link" href="/about">关于我</a>
                
            </nav>
            
                
                <nav id="sub-nav">
                    <div class="profile" id="profile-nav">
                        <a id="profile-anchor" href="javascript:;">
                            <img class="avatar" src="/css/images/avatar.png" />
                            <i class="fa fa-caret-down"></i>
                        </a>
                    </div>
                </nav>
            
            <div id="search-form-wrap">

    <form class="search-form">
        <input type="text" class="ins-search-input search-form-input" placeholder="搜索" />
        <!--button type="submit" class="search-form-submit"></button-->
    </form>
    <div class="ins-search">
    <div class="ins-search-mask"></div>
    <div class="ins-search-container">
        <div class="ins-input-wrapper">
            <input type="text" class="ins-search-input" placeholder="想要查找什么..." />
            <span class="ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/',
        CONTENT_URL: '/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
<script src="/js/insight.js"></script>

</div>
        </div>
    </div>
    <div id="main-nav-mobile" class="header-sub header-inner">
        <table class="menu outer">
            <tr>
                
                    <td ><a  class="main-nav-link" href="/.">首页</a></td>
                
                    <td ><a  class="main-nav-link" href="/archives">时间轴</a></td>
                
                    <td ><a  class="main-nav-link" href="/categories">文章专题</a></td>
                
                    <td ><a  class="main-nav-link" href="/tags">标签云</a></td>
                
                    <td ><a  class="main-nav-link" href="/about">关于我</a></td>
                
                <td>
                    
    <div class="search-form">
        <input type="text" class="ins-search-input search-form-input" placeholder="搜索" />
    </div>

                </td>
            </tr>
        </table>
    </div>
</header>

        <div class="outer">
            
                

<aside id="profile">
    <div class="inner profile-inner">
        <div class="base-info profile-block">
            <img id="avatar" src="/css/images/avatar.png" />
            <h2 id="name">恒宇少年</h2>
            <h3 id="title">Java软件工程师 &amp; 程序猿</h3>
            <span id="location"><i class="fa fa-map-marker"></i>山东, 济南</span>
            <a id="follow" target="_blank" href="https://www.jianshu.com/u/092df3f77bca">关注我</a>
        </div>
        <div class="article-info profile-block">
            <div class="article-info-block">
                43
                <span>文章</span>
            </div>
            <div class="article-info-block">
                2
                <span>标签</span>
            </div>
        </div>
        
        <div class="profile-block social-links">
            <table>
                <tr>
                    
                    
                    <td>
                        <a href="http://github.com/ppoffice/hexo-theme-icarus" target="_blank" title="github" class=tooltip>
                            <i class="fa fa-github"></i>
                        </a>
                    </td>
                    
                    <td>
                        <a href="/" target="_blank" title="twitter" class=tooltip>
                            <i class="fa fa-twitter"></i>
                        </a>
                    </td>
                    
                    <td>
                        <a href="/" target="_blank" title="facebook" class=tooltip>
                            <i class="fa fa-facebook"></i>
                        </a>
                    </td>
                    
                    <td>
                        <a href="/" target="_blank" title="dribbble" class=tooltip>
                            <i class="fa fa-dribbble"></i>
                        </a>
                    </td>
                    
                    <td>
                        <a href="/" target="_blank" title="rss" class=tooltip>
                            <i class="fa fa-rss"></i>
                        </a>
                    </td>
                    
                </tr>
            </table>
        </div>
        
    </div>
</aside>

            
            <section id="main"><article id="post-spring-boot-chapter-44" class="article article-type-post" itemscope itemprop="blogPost">
    <div class="article-inner">
        
        
            <header class="article-header">
                
    
        <h1 class="article-title" itemprop="name">
            第四十四章： 基于SpringBoot &amp; AOP完成统一资源自动查询映射
        </h1>
    

                
                    <div class="article-meta">
                        
    <div class="article-date">
        <i class="fa fa-calendar"></i>
        <a href="/spring-boot-chapter-44/">
            <time datetime="2017-12-30T16:00:00.000Z" itemprop="datePublished">2017-12-31</time>
        </a>
    </div>


                        
    <div class="article-category">
    	<i class="fa fa-folder"></i>
        <a class="article-category-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a>
    </div>

                        
    <div class="article-tag">
        <i class="fa fa-tag"></i>
        <a class="tag-link" href="/tags/SpringBoot/">SpringBoot</a>
    </div>

                    </div>
                
            </header>
        
        
        <div class="article-entry" itemprop="articleBody">
        
            
            <p>本章内容比较偏向系统设计方面，简单的封装就可以应用到系统中使用，从而提高我们的编码效率以及代码的可读性。统一资源在系统内是不可避免的模块，资源分类也有很多种，比较常见如：图片资源、文本资源、视频资源等，那么资源统一处理的好处是什么呢？大家有可能会有疑问，我把资源存放到业务表内岂不更好吗？这样查询起来也方便，并不需要关联资源信息表！当然设计不分好坏，只有更适合、更简单！接下来带着疑问进入本章的内容。<br><a id="more"></a></p>
<h1 id="本章目标"><a href="#本章目标" class="headerlink" title="本章目标"></a>本章目标</h1><p>基于<code>SpringBoot</code>平台结合<code>AOP</code>完成统一资源的自动查询映射。</p>
<h1 id="构建项目"><a href="#构建项目" class="headerlink" title="构建项目"></a>构建项目</h1><p>本章使用到的依赖相对来说比较多，大致：<code>Web</code>、<code>MapStruct</code>、<code>SpringDataJpa</code>、<code>LomBok</code>等，数据库方面采用<code>MySQL</code>来作为数据支持。</p>
<h1 id="SpringBoot-企业级核心技术学习专题"><a href="#SpringBoot-企业级核心技术学习专题" class="headerlink" title="SpringBoot 企业级核心技术学习专题"></a>SpringBoot 企业级核心技术学习专题</h1><table>
<thead>
<tr>
<th style="text-align:center">专题</th>
<th style="text-align:left">专题名称</th>
<th style="text-align:left">专题描述</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">001</td>
<td style="text-align:left"><a href="http://www.jianshu.com/c/3f69deddbed3" target="_blank" rel="noopener">Spring Boot 核心技术</a></td>
<td style="text-align:left">讲解SpringBoot一些企业级层面的核心组件</td>
</tr>
<tr>
<td style="text-align:center">002</td>
<td style="text-align:left"><a href="https://gitee.com/hengboy/spring-boot-chapter" target="_blank" rel="noopener">Spring Boot 核心技术章节源码</a></td>
<td style="text-align:left">Spring Boot 核心技术简书每一篇文章码云对应源码</td>
</tr>
<tr>
<td style="text-align:center">003</td>
<td style="text-align:left"><a href="http://www.jianshu.com/c/1faac22666e7" target="_blank" rel="noopener">Spring Cloud 核心技术</a></td>
<td style="text-align:left">对Spring Cloud核心技术全面讲解</td>
</tr>
<tr>
<td style="text-align:center">004</td>
<td style="text-align:left"><a href="https://gitee.com/hengboy/spring-cloud-chapter" target="_blank" rel="noopener">Spring Cloud 核心技术章节源码</a></td>
<td style="text-align:left">Spring Cloud 核心技术简书每一篇文章对应源码</td>
</tr>
<tr>
<td style="text-align:center">005</td>
<td style="text-align:left"><a href="http://www.jianshu.com/c/ab4789177827" target="_blank" rel="noopener">QueryDSL 核心技术</a></td>
<td style="text-align:left">全面讲解QueryDSL核心技术以及基于SpringBoot整合SpringDataJPA</td>
</tr>
<tr>
<td style="text-align:center">006</td>
<td style="text-align:left"><a href="http://www.jianshu.com/c/f1b269bb2fd6" target="_blank" rel="noopener">SpringDataJPA 核心技术</a></td>
<td style="text-align:left">全面讲解SpringDataJPA核心技术</td>
</tr>
</tbody>
</table>
<h3 id="数据初始化"><a href="#数据初始化" class="headerlink" title="数据初始化"></a>数据初始化</h3><p>本章用到的数据表结构以及初始化的数据之前都是放在项目的<code>resources</code>目录下，为了大家使用方面我在这里直接贴出来，如下所示：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br></pre></td><td class="code"><pre><span class="line">--</span><br><span class="line">-- Table structure for table `hy_common_resource`</span><br><span class="line">--</span><br><span class="line"></span><br><span class="line">DROP TABLE IF EXISTS `hy_common_resource`;</span><br><span class="line">/*!40101 SET @saved_cs_client     = @@character_set_client */;</span><br><span class="line">/*!40101 SET character_set_client = utf8 */;</span><br><span class="line">CREATE TABLE `hy_common_resource` (</span><br><span class="line">  `CR_ID` int(11) NOT NULL AUTO_INCREMENT COMMENT &apos;主键自增&apos;,</span><br><span class="line">  `CR_TARGET_ID` varchar(36) DEFAULT &apos;NULL&apos; COMMENT &apos;所属目标编号，关联其他信息表主键，如：用户头像关联用户编号&apos;,</span><br><span class="line">  `CR_TYPE_ID` varchar(36) DEFAULT NULL COMMENT &apos;资源类型编号&apos;,</span><br><span class="line">  `CR_URL` varchar(200) DEFAULT &apos;NULL&apos; COMMENT &apos;资源路径，如：图片地址&apos;,</span><br><span class="line">  `CR_CREATE_TIME` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT &apos;资源添加时间&apos;,</span><br><span class="line">  `CR_ORDER` int(11) DEFAULT 0 COMMENT &apos;排序字段&apos;,</span><br><span class="line">  PRIMARY KEY (`CR_ID`)</span><br><span class="line">) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT=&apos;系统资源信息表&apos;;</span><br><span class="line">/*!40101 SET character_set_client = @saved_cs_client */;</span><br><span class="line"></span><br><span class="line">--</span><br><span class="line">-- Dumping data for table `hy_common_resource`</span><br><span class="line">--</span><br><span class="line"></span><br><span class="line">LOCK TABLES `hy_common_resource` WRITE;</span><br><span class="line">/*!40000 ALTER TABLE `hy_common_resource` DISABLE KEYS */;</span><br><span class="line">INSERT INTO `hy_common_resource` VALUES (1,&apos;bc4c8e38-edd6-11e7-969c-3c15c2e4a8a6&apos;,&apos;ce66916c-edd7-11e7-969c-3c15c2e4a8a6&apos;,&apos;https://upload.jianshu.io/users/upload_avatars/4461954/f09ba256-f6db-41ed-a4ac-b2d23737f0ac.jpg?imageMogr2/auto-orient/strip|imageView2/1/w/96/h/96&apos;,&apos;2017-12-31 03:08:46&apos;,0),(2,&apos;bc4c8e38-edd6-11e7-969c-3c15c2e4a8a6&apos;,&apos;f84f12c4-edd7-11e7-969c-3c15c2e4a8a6&apos;,&apos;https://upload.jianshu.io/collections/images/358868/android.graphics.Bitmap_d88b4de.jpeg?imageMogr2/auto-orient/strip|imageView2/1/w/240/h/240&apos;,&apos;2017-12-31 03:12:38&apos;,0),(3,&apos;bc4c8e38-edd6-11e7-969c-3c15c2e4a8a6&apos;,&apos;f84f12c4-edd7-11e7-969c-3c15c2e4a8a6&apos;,&apos;https://upload.jianshu.io/collections/images/522928/kafka_diagram.png?imageMogr2/auto-orient/strip|imageView2/1/w/240/h/240&apos;,&apos;2017-12-31 09:13:32&apos;,0);</span><br><span class="line">/*!40000 ALTER TABLE `hy_common_resource` ENABLE KEYS */;</span><br><span class="line">UNLOCK TABLES;</span><br><span class="line"></span><br><span class="line">--</span><br><span class="line">-- Table structure for table `hy_common_resource_type`</span><br><span class="line">--</span><br><span class="line"></span><br><span class="line">DROP TABLE IF EXISTS `hy_common_resource_type`;</span><br><span class="line">/*!40101 SET @saved_cs_client     = @@character_set_client */;</span><br><span class="line">/*!40101 SET character_set_client = utf8 */;</span><br><span class="line">CREATE TABLE `hy_common_resource_type` (</span><br><span class="line">  `CRT_ID` varchar(36) NOT NULL COMMENT &apos;类型编号&apos;,</span><br><span class="line">  `CRT_NAME` varchar(20) DEFAULT NULL COMMENT &apos;类型名称&apos;,</span><br><span class="line">  `CRT_FLAG` varchar(30) DEFAULT NULL COMMENT &apos;资源标识&apos;,</span><br><span class="line">  `CRT_CREATE_TIME` timestamp NOT NULL DEFAULT current_timestamp() COMMENT &apos;创建时间&apos;,</span><br><span class="line">  PRIMARY KEY (`CRT_ID`)</span><br><span class="line">) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=&apos;资源类型信息表&apos;;</span><br><span class="line">/*!40101 SET character_set_client = @saved_cs_client */;</span><br><span class="line"></span><br><span class="line">--</span><br><span class="line">-- Dumping data for table `hy_common_resource_type`</span><br><span class="line">--</span><br><span class="line"></span><br><span class="line">LOCK TABLES `hy_common_resource_type` WRITE;</span><br><span class="line">/*!40000 ALTER TABLE `hy_common_resource_type` DISABLE KEYS */;</span><br><span class="line">INSERT INTO `hy_common_resource_type` VALUES (&apos;ce66916c-edd7-11e7-969c-3c15c2e4a8a6&apos;,&apos;用户头像&apos;,&apos;USER_HEAD_IMAGE&apos;,&apos;2017-12-31 03:07:59&apos;),(&apos;f84f12c4-edd7-11e7-969c-3c15c2e4a8a6&apos;,&apos;用户背景图片&apos;,&apos;USER_BACK_IMAGE&apos;,&apos;2017-12-31 03:09:09&apos;);</span><br><span class="line">/*!40000 ALTER TABLE `hy_common_resource_type` ENABLE KEYS */;</span><br><span class="line">UNLOCK TABLES;</span><br><span class="line"></span><br><span class="line">--</span><br><span class="line">-- Table structure for table `hy_user_info`</span><br><span class="line">--</span><br><span class="line"></span><br><span class="line">DROP TABLE IF EXISTS `hy_user_info`;</span><br><span class="line">/*!40101 SET @saved_cs_client     = @@character_set_client */;</span><br><span class="line">/*!40101 SET character_set_client = utf8 */;</span><br><span class="line">CREATE TABLE `hy_user_info` (</span><br><span class="line">  `UI_ID` varchar(36) NOT NULL COMMENT &apos;主键&apos;,</span><br><span class="line">  `UI_NAME` varchar(10) DEFAULT NULL COMMENT &apos;名称&apos;,</span><br><span class="line">  `UI_NICK_NAME` varchar(20) DEFAULT NULL COMMENT &apos;昵称&apos;,</span><br><span class="line">  `UI_AGE` int(11) DEFAULT NULL COMMENT &apos;年龄&apos;,</span><br><span class="line">  `UI_ADDRESS` varchar(50) DEFAULT NULL COMMENT &apos;所居地&apos;,</span><br><span class="line">  PRIMARY KEY (`UI_ID`)</span><br><span class="line">) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=&apos;用户基本信息表&apos;;</span><br><span class="line">/*!40101 SET character_set_client = @saved_cs_client */;</span><br><span class="line"></span><br><span class="line">--</span><br><span class="line">-- Dumping data for table `hy_user_info`</span><br><span class="line">--</span><br><span class="line"></span><br><span class="line">LOCK TABLES `hy_user_info` WRITE;</span><br><span class="line">/*!40000 ALTER TABLE `hy_user_info` DISABLE KEYS */;</span><br><span class="line">INSERT INTO `hy_user_info` VALUES (&apos;bc4c8e38-edd6-11e7-969c-3c15c2e4a8a6&apos;,&apos;hengboy&apos;,&apos;恒宇少年&apos;,23,&apos;山东省济南市&apos;);</span><br><span class="line">/*!40000 ALTER TABLE `hy_user_info` ENABLE KEYS */;</span><br><span class="line">UNLOCK TABLES;</span><br></pre></td></tr></table></figure></p>
<blockquote>
<p>用到的数据库为<code>resources</code>，可以自行创建或者更换其他数据库使用。</p>
<h3 id="搭建项目"><a href="#搭建项目" class="headerlink" title="搭建项目"></a>搭建项目</h3><p>本章我们把统一资源单独拿出来作为一个项目子模块来构建，而用户服务作为另外一个单独模块构建，下面先来贴出父项目的<code>pom.xml</code>配置文件内容，如下所示：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br></pre></td><td class="code"><pre><span class="line">....//</span><br><span class="line">&lt;parent&gt;</span><br><span class="line">        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">        &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;</span><br><span class="line">        &lt;version&gt;1.5.9.RELEASE&lt;/version&gt;</span><br><span class="line">        &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;</span><br><span class="line">    &lt;/parent&gt;</span><br><span class="line"></span><br><span class="line">    &lt;properties&gt;</span><br><span class="line">        &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;</span><br><span class="line">        &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;</span><br><span class="line">        &lt;java.version&gt;1.8&lt;/java.version&gt;</span><br><span class="line">        &lt;org.mapstruct.version&gt;1.2.0.Final&lt;/org.mapstruct.version&gt;</span><br><span class="line">    &lt;/properties&gt;</span><br><span class="line"></span><br><span class="line">    &lt;dependencies&gt;</span><br><span class="line">        &lt;!--mapStruct--&gt;</span><br><span class="line">        &lt;dependency&gt;</span><br><span class="line">            &lt;groupId&gt;org.mapstruct&lt;/groupId&gt;</span><br><span class="line">            &lt;artifactId&gt;mapstruct-jdk8&lt;/artifactId&gt;</span><br><span class="line">            &lt;version&gt;$&#123;org.mapstruct.version&#125;&lt;/version&gt;</span><br><span class="line">        &lt;/dependency&gt;</span><br><span class="line">        &lt;dependency&gt;</span><br><span class="line">            &lt;groupId&gt;org.mapstruct&lt;/groupId&gt;</span><br><span class="line">            &lt;artifactId&gt;mapstruct-processor&lt;/artifactId&gt;</span><br><span class="line">            &lt;version&gt;$&#123;org.mapstruct.version&#125;&lt;/version&gt;</span><br><span class="line">            &lt;scope&gt;provided&lt;/scope&gt;</span><br><span class="line">        &lt;/dependency&gt;</span><br><span class="line">        &lt;dependency&gt;</span><br><span class="line">            &lt;groupId&gt;javax.inject&lt;/groupId&gt;</span><br><span class="line">            &lt;artifactId&gt;javax.inject&lt;/artifactId&gt;</span><br><span class="line">            &lt;version&gt;1&lt;/version&gt;</span><br><span class="line">        &lt;/dependency&gt;</span><br><span class="line">        &lt;!--Spring data jpa--&gt;</span><br><span class="line">        &lt;dependency&gt;</span><br><span class="line">            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">            &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;</span><br><span class="line">        &lt;/dependency&gt;</span><br><span class="line">        &lt;!--web--&gt;</span><br><span class="line">        &lt;dependency&gt;</span><br><span class="line">            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">            &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;</span><br><span class="line">        &lt;/dependency&gt;</span><br><span class="line">        &lt;!--MySQL--&gt;</span><br><span class="line">        &lt;dependency&gt;</span><br><span class="line">            &lt;groupId&gt;mysql&lt;/groupId&gt;</span><br><span class="line">            &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;</span><br><span class="line">            &lt;scope&gt;runtime&lt;/scope&gt;</span><br><span class="line">        &lt;/dependency&gt;</span><br><span class="line">        &lt;!--Lombok--&gt;</span><br><span class="line">        &lt;dependency&gt;</span><br><span class="line">            &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;</span><br><span class="line">            &lt;artifactId&gt;lombok&lt;/artifactId&gt;</span><br><span class="line">            &lt;optional&gt;true&lt;/optional&gt;</span><br><span class="line">        &lt;/dependency&gt;</span><br><span class="line">        &lt;!--druid--&gt;</span><br><span class="line">        &lt;dependency&gt;</span><br><span class="line">            &lt;groupId&gt;com.alibaba&lt;/groupId&gt;</span><br><span class="line">            &lt;artifactId&gt;druid-spring-boot-starter&lt;/artifactId&gt;</span><br><span class="line">            &lt;version&gt;1.1.6&lt;/version&gt;</span><br><span class="line">        &lt;/dependency&gt;</span><br><span class="line">    &lt;/dependencies&gt;</span><br><span class="line">....//</span><br></pre></td></tr></table></figure></p>
</blockquote>
<p>接下来我们开始创建<code>common-resource</code>子模块，将资源处理完全独立出来，在创建子模块时要注意<code>package</code>命名要保证可以被<code>SpringBoot</code>运行时扫描到！！！</p>
<h4 id="common-resource"><a href="#common-resource" class="headerlink" title="common-resource"></a>common-resource</h4><p>我们需要先创建一个<code>BaseEntity</code>作为所有实体的父类存在，如下所示：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 所有实体的父类</span><br><span class="line"> * 作为类型标识存在</span><br><span class="line"> * @author yuqiyu</span><br><span class="line"> * ========================</span><br><span class="line"> * Created with IntelliJ IDEA.</span><br><span class="line"> * User：恒宇少年</span><br><span class="line"> * Date：2017/12/31</span><br><span class="line"> * Time：下午3:35</span><br><span class="line"> * 码云：http://git.oschina.net/jnyqy</span><br><span class="line"> * ========================</span><br><span class="line"> */</span><br><span class="line">public class BaseEntity</span><br><span class="line">    implements Serializable&#123;&#125;</span><br></pre></td></tr></table></figure></p>
<p>该类仅仅实现了<code>Serializable</code>接口，在创建业务实体时需要继承该类，这也是基本的设计规则，方便后期添加全局统一的字段或者配置。</p>
<ul>
<li><p>资源实体</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 资源实体</span><br><span class="line"> * @author yuqiyu</span><br><span class="line"> * ========================</span><br><span class="line"> * Created with IntelliJ IDEA.</span><br><span class="line"> * User：恒宇少年</span><br><span class="line"> * Date：2017/12/31</span><br><span class="line"> * Time：上午11:21</span><br><span class="line"> * 码云：http://git.oschina.net/jnyqy</span><br><span class="line"> * ========================</span><br><span class="line"> */</span><br><span class="line">@Data</span><br><span class="line">@Entity</span><br><span class="line">@Table(name = &quot;hy_common_resource&quot;)</span><br><span class="line">public class CommonResourceEntity</span><br><span class="line">    extends BaseEntity</span><br><span class="line">&#123;</span><br><span class="line">    /**</span><br><span class="line">     * 资源编号</span><br><span class="line">     */</span><br><span class="line">    @Column(name = &quot;CR_ID&quot;)</span><br><span class="line">    @Id</span><br><span class="line">    @GeneratedValue</span><br><span class="line">    private Integer resourceId;</span><br><span class="line">    /**</span><br><span class="line">     * 资源所属目标编号</span><br><span class="line">     */</span><br><span class="line">    @Column(name = &quot;CR_TARGET_ID&quot;)</span><br><span class="line">    private String targetId;</span><br><span class="line">    /**</span><br><span class="line">     * 类型编号</span><br><span class="line">     */</span><br><span class="line">    @Column(name = &quot;CR_TYPE_ID&quot;)</span><br><span class="line">    private String typeId;</span><br><span class="line">    /**</span><br><span class="line">     * 资源路径</span><br><span class="line">     */</span><br><span class="line">    @Column(name = &quot;CR_URL&quot;)</span><br><span class="line">    private String resourceUrl;</span><br><span class="line">    /**</span><br><span class="line">     * 创建时间</span><br><span class="line">     */</span><br><span class="line">    @Column(name = &quot;CR_CREATE_TIME&quot;)</span><br><span class="line">    private Timestamp createTime;</span><br><span class="line">    /**</span><br><span class="line">     * 排序</span><br><span class="line">     */</span><br><span class="line">    @Column(name = &quot;CR_ORDER&quot;)</span><br><span class="line">    private int order;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>资源类型实体</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 资源类型实体</span><br><span class="line"> * @author yuqiyu</span><br><span class="line"> * ========================</span><br><span class="line"> * Created with IntelliJ IDEA.</span><br><span class="line"> * User：恒宇少年</span><br><span class="line"> * Date：2017/12/31</span><br><span class="line"> * Time：上午11:22</span><br><span class="line"> * 码云：http://git.oschina.net/jnyqy</span><br><span class="line"> * ========================</span><br><span class="line"> */</span><br><span class="line">@Data</span><br><span class="line">@Entity</span><br><span class="line">@Table(name = &quot;hy_common_resource_type&quot;)</span><br><span class="line">public class CommonResourceTypeEntity</span><br><span class="line">    extends BaseEntity</span><br><span class="line">&#123;</span><br><span class="line">    /**</span><br><span class="line">     * 类型编号</span><br><span class="line">     */</span><br><span class="line">    @Id</span><br><span class="line">    @Column(name = &quot;CRT_ID&quot;)</span><br><span class="line">    @GeneratedValue(generator = &quot;system-uuid&quot;)</span><br><span class="line">    @GenericGenerator(name = &quot;system-uuid&quot;, strategy = &quot;uuid&quot;)</span><br><span class="line">    private String id;</span><br><span class="line">    /**</span><br><span class="line">     * 类型名称</span><br><span class="line">     */</span><br><span class="line">    @Column(name = &quot;CRT_NAME&quot;)</span><br><span class="line">    private String name;</span><br><span class="line">    /**</span><br><span class="line">     * 类型标识</span><br><span class="line">     */</span><br><span class="line">    @Column(name = &quot;CRT_FLAG&quot;)</span><br><span class="line">    private String flag;</span><br><span class="line">    /**</span><br><span class="line">     * 类型添加时间</span><br><span class="line">     */</span><br><span class="line">    @Column(name = &quot;CRT_CREATE_TIME&quot;)</span><br><span class="line">    private Timestamp createTime;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>下面我们来创建对应实体的数据接口，我们采用<code>SpringDataJPA</code>的方法名查询规则来查询对应的数据。</p>
<ul>
<li><p>资源数据接口</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 资源数据接口</span><br><span class="line"> * @author yuqiyu</span><br><span class="line"> * ========================</span><br><span class="line"> * Created with IntelliJ IDEA.</span><br><span class="line"> * User：恒宇少年</span><br><span class="line"> * Date：2017/12/31</span><br><span class="line"> * Time：上午11:31</span><br><span class="line"> * 码云：http://git.oschina.net/jnyqy</span><br><span class="line"> * ========================</span><br><span class="line"> */</span><br><span class="line">public interface CommonResourceRepository</span><br><span class="line">    extends JpaRepository&lt;CommonResourceEntity,Integer&gt;</span><br><span class="line">&#123;</span><br><span class="line">    /**</span><br><span class="line">     * 根据类型编号 &amp; 目标编号查询出资源实体</span><br><span class="line">     * @param typeId 类型编号</span><br><span class="line">     * @param targetId 目标编号</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    List&lt;CommonResourceEntity&gt; findByTypeIdAndTargetId(String typeId, String targetId);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>资源类型数据接口</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 资源类型数据接口</span><br><span class="line"> * @author yuqiyu</span><br><span class="line"> * ========================</span><br><span class="line"> * Created with IntelliJ IDEA.</span><br><span class="line"> * User：恒宇少年</span><br><span class="line"> * Date：2017/12/31</span><br><span class="line"> * Time：上午11:32</span><br><span class="line"> * 码云：http://git.oschina.net/jnyqy</span><br><span class="line"> * ========================</span><br><span class="line"> */</span><br><span class="line">public interface CommonResourceTypeRepository</span><br><span class="line">    extends JpaRepository&lt;CommonResourceTypeEntity,String&gt;</span><br><span class="line">&#123;</span><br><span class="line">    /**</span><br><span class="line">     * 根据类别标识查询</span><br><span class="line">     * @param flag 资源类型标识</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    CommonResourceTypeEntity findTopByFlag(String flag);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>接下来我们开始编写根据资源类型获取指定目标编号的资源列表业务逻辑方法，创建名为<code>CommonResourceService</code>统一资源业务逻辑实现类，如下所示：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 公共资源业务逻辑实现类</span><br><span class="line"> * @author yuqiyu</span><br><span class="line"> * ========================</span><br><span class="line"> * Created with IntelliJ IDEA.</span><br><span class="line"> * User：恒宇少年</span><br><span class="line"> * Date：2017/12/31</span><br><span class="line"> * Time：下午4:18</span><br><span class="line"> * 码云：http://git.oschina.net/jnyqy</span><br><span class="line"> * ========================</span><br><span class="line"> */</span><br><span class="line">@Service</span><br><span class="line">@Transactional(rollbackFor = Exception.class)</span><br><span class="line">public class CommonResourceService &#123;</span><br><span class="line">    /**</span><br><span class="line">     * 资源类型数据接口</span><br><span class="line">     */</span><br><span class="line">    @Autowired</span><br><span class="line">    private CommonResourceTypeRepository resourceTypeRepository;</span><br><span class="line">    /**</span><br><span class="line">     * 资源数据接口</span><br><span class="line">     */</span><br><span class="line">    @Autowired</span><br><span class="line">    private CommonResourceRepository resourceRepository;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 根据资源标识 &amp; 所属目标编号查询资源路径路边</span><br><span class="line">     *</span><br><span class="line">     * @param resourceFlag 资源标识</span><br><span class="line">     * @param targetId     目标编号</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    public List&lt;String&gt; selectUrlsByFlag(CommonResourceFlag resourceFlag, String targetId) throws Exception &#123;</span><br><span class="line">        /**</span><br><span class="line">         * 获取资源类型</span><br><span class="line">         */</span><br><span class="line">        CommonResourceTypeEntity resourceType = selectResourceTypeByFlag(resourceFlag);</span><br><span class="line">        /**</span><br><span class="line">         * 查询该目标编号 &amp; 类型的资源列表</span><br><span class="line">         */</span><br><span class="line">        List&lt;CommonResourceEntity&gt; resources = resourceRepository.findByTypeIdAndTargetId(resourceType.getId(), targetId);</span><br><span class="line"></span><br><span class="line">        return convertUrl(resources);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 转换路径</span><br><span class="line">     * 通过实体集合转换成路径集合</span><br><span class="line">     *</span><br><span class="line">     * @param resources 资源实体列表</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    List&lt;String&gt; convertUrl(List&lt;CommonResourceEntity&gt; resources) &#123;</span><br><span class="line">        List&lt;String&gt; urls = null;</span><br><span class="line">        if (!ObjectUtils.isEmpty(resources)) &#123;</span><br><span class="line">            urls = new ArrayList();</span><br><span class="line">            for (CommonResourceEntity resource : resources) &#123;</span><br><span class="line">                urls.add(resource.getResourceUrl());</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        return urls;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 根据资源类型标识查询资源类型基本信息</span><br><span class="line">     *</span><br><span class="line">     * @param resourceFlag 资源类型标识</span><br><span class="line">     * @return</span><br><span class="line">     * @throws Exception</span><br><span class="line">     */</span><br><span class="line">    CommonResourceTypeEntity selectResourceTypeByFlag(CommonResourceFlag resourceFlag) throws Exception &#123;</span><br><span class="line">        /**</span><br><span class="line">         * 查询资源类型</span><br><span class="line">         */</span><br><span class="line">        CommonResourceTypeEntity resourceType = resourceTypeRepository.findTopByFlag(resourceFlag.getName());</span><br><span class="line">        if (ObjectUtils.isEmpty(resourceFlag)) &#123;</span><br><span class="line">            throw new Exception(&quot;未查询到资源&quot;);</span><br><span class="line">        &#125;</span><br><span class="line">        return resourceType;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>在<code>CommonResourceService</code>提供了对外的方法<code>selectUrlsByFlag</code>可以查询指定目标编号 &amp; 指定类型的多个资源地址。</p>
<h4 id="统一资源映射"><a href="#统一资源映射" class="headerlink" title="统一资源映射"></a>统一资源映射</h4><p>在<code>common-resource</code>子模块项目内添加统一资源的相关映射内容，我们预计的目标效果是根据我们自定义的注解结合<code>AOP</code>来实现指定方法的结果处理映射，我们需要创建两个自定义的注解来完成我们的预想效果，注解分别为：<code>ResourceField</code>、<code>ResourceMethod</code>，下面我们来看看<code>ResourceField</code>注解的属性定义，如下所示：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * 配置统一资源字段</span><br><span class="line"> * 该注解配置在普通字段上，根据配置信息自动查询对应的资源地址</span><br><span class="line"> * Demo：</span><br><span class="line"> *</span><br><span class="line"> * @ResourceField(flag=CommonResourceFlagEnum.SHOP_COVER_IMG)</span><br><span class="line"> * private String shopCoverImage;</span><br><span class="line"> *</span><br><span class="line"> * 其中multiple不需要配置，因为封面只有一张，使用默认值即可</span><br><span class="line"> * flag设置为对应的资源标识，资源类型不存在时不执行查询</span><br><span class="line"> * @ResourceTargetId 如果注解不存在或目标编号不存在或者为null、&quot;&quot;时不执行查询资源</span><br><span class="line"> *</span><br><span class="line"> * @author：于起宇 &lt;br/&gt;</span><br><span class="line"> * ===============================</span><br><span class="line"> * Created with Eclipse.</span><br><span class="line"> * Date：2017/12/31</span><br><span class="line"> * Time：13:11</span><br><span class="line"> * 简书：http://www.jianshu.com/u/092df3f77bca</span><br><span class="line"> * ================================</span><br><span class="line"> */</span><br><span class="line">@Retention(RetentionPolicy.RUNTIME)</span><br><span class="line">@Target(ElementType.FIELD)</span><br><span class="line">@Documented</span><br><span class="line">public @interface ResourceField &#123;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 读取资源是单条或者多条</span><br><span class="line">     * true：读取多条资源地址，对应设置到List&lt;String&gt;集合内</span><br><span class="line">     * false：读取单条资源地址，对应设置配置ResourceField注解的字段value</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    boolean multiple() default false;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 配置读取统一资源的标识类型</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    CommonResourceFlag flag();</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 如果配置该字段则不会去找@Id配置的字段</span><br><span class="line">     * 该字段默认为空，则默认使用@Id标注的字段的值作为查询统一资源的target_id</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    String targetIdField() default &quot;&quot;;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p><code>ResourceField</code>注解用于配置在查询结果的字段上，如：我们查询用户头像时定义的字段为<code>userHeadImage</code>，我们这时仅仅需要在<code>userHeadImage</code>字段上添加<code>ResourceField</code>即可。<br>另外一个注解<code>ResourceMethod</code>的作用仅仅是为了<code>AOP</code>根据该注解切面方法，也是只有被该注解切面的方法才会去执行<code>AOP</code>切面方法的返回值进行处理，代码如下所示：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 配置指定方法将会被AOP切面类ResourceAspect所拦截</span><br><span class="line"> * 拦截后会根据自定义注解进行查询资源 &amp; 设置资源等逻辑</span><br><span class="line"> * @author：于起宇 &lt;br/&gt;</span><br><span class="line"> * ===============================</span><br><span class="line"> * Created with Eclipse.</span><br><span class="line"> * Date：2017/12/15</span><br><span class="line"> * Time：14:04</span><br><span class="line"> * 简书：http://www.jianshu.com/u/092df3f77bca</span><br><span class="line"> * ================================</span><br><span class="line"> */</span><br><span class="line">@Retention(RetentionPolicy.RUNTIME)</span><br><span class="line">@Target(ElementType.METHOD)</span><br><span class="line">@Documented</span><br><span class="line">public @interface ResourceMethod &#123; &#125;</span><br></pre></td></tr></table></figure></p>
<p>我们的自定义注解已经编写完成，转过头来我们先看看<code>@Around</code>切面方法所需要的逻辑实现方法，创建<code>ResourcePushService</code>接口添加如下两个方法：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * 统一资源设置业务逻辑定义接口</span><br><span class="line"> * @author：于起宇 &lt;br/&gt;</span><br><span class="line"> * ===============================</span><br><span class="line"> * Created with Eclipse.</span><br><span class="line"> * Date：2017/12/15</span><br><span class="line"> * Time：14:58</span><br><span class="line"> * 简书：http://www.jianshu.com/u/092df3f77bca</span><br><span class="line"> * ================================</span><br><span class="line"> */</span><br><span class="line">public interface ResourcePushService</span><br><span class="line">&#123;</span><br><span class="line">    /**</span><br><span class="line">     * 设置单个实例的资源信息</span><br><span class="line">     * @param object 需要设置资源的实例</span><br><span class="line">     */</span><br><span class="line">    void push(Object object) throws Exception;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 设置多个实例的资源信息</span><br><span class="line">     * @param objectList 需要设置资源的实例列表</span><br><span class="line">     */</span><br><span class="line">    void push(List&lt;Object&gt; objectList) throws Exception;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>分别提供了设置单个、多个资源的方法，由于实现类内容比较多这里就不贴出具体的实现代码了，详细请下载源码进行查看，源码地址：<a href="https://gitee.com/hengboy/spring-boot-chapter" target="_blank" rel="noopener">spring-boot-chapter</a>内的<code>Chapter44</code>项目。</p>
<h5 id="资源切面类"><a href="#资源切面类" class="headerlink" title="资源切面类"></a>资源切面类</h5><p>我们一直都在说资源统一切面映射，那么我们的资源的切面该如何去配置切面切入点呢？在之前我们创建了<code>ResourceMethod</code>注解，我们就用它作为方法切入点完成切面的<code>环绕</code>实现，  <code>ResourceAspect</code>代码如下所示：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 统一资源Aop切面定义</span><br><span class="line"> * 根据自定义注解配置自动设置配置的资源类型到指定的字段</span><br><span class="line"> * @author：于起宇 &lt;br/&gt;</span><br><span class="line"> * ===============================</span><br><span class="line"> * Created with Eclipse.</span><br><span class="line"> * Date：2017/12/15</span><br><span class="line"> * Time：14:05</span><br><span class="line"> * 简书：http://www.jianshu.com/u/092df3f77bca</span><br><span class="line"> * ================================</span><br><span class="line"> */</span><br><span class="line">@Component</span><br><span class="line">@Aspect</span><br><span class="line">public class ResourceAspect</span><br><span class="line">&#123;</span><br><span class="line">    /**</span><br><span class="line">     * logback</span><br><span class="line">     */</span><br><span class="line">    Logger logger = LoggerFactory.getLogger(ResourceAspect.class);</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 资源处理业务逻辑</span><br><span class="line">     */</span><br><span class="line">    @Autowired</span><br><span class="line">    @Qualifier(&quot;ResourcePushSupport&quot;)</span><br><span class="line">    ResourcePushService resourcePushService;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 资源设置切面方法</span><br><span class="line">     * 拦截配置了@ResourceMethod注解的class method，cglib仅支持class 方法切面，接口切面不支持</span><br><span class="line">     * @param proceedingJoinPoint 切面方法实例</span><br><span class="line">     * @param resourceMethod 方法注解实例</span><br><span class="line">     * @return</span><br><span class="line">     * @throws Throwable</span><br><span class="line">     */</span><br><span class="line">    @Around(value = &quot;@annotation(resourceMethod)&quot;)</span><br><span class="line">    public Object resourcePutAround(ProceedingJoinPoint proceedingJoinPoint, ResourceMethod resourceMethod)</span><br><span class="line">        throws Throwable</span><br><span class="line">    &#123;</span><br><span class="line">        logger.info(&quot;开始处理资源自动设置Aop切面逻辑&quot;);</span><br><span class="line">        /**</span><br><span class="line">         * 执行方法，获取返回值</span><br><span class="line">         */</span><br><span class="line">        Object result = proceedingJoinPoint.proceed();</span><br><span class="line">        if(StringUtils.isEmpty(result)) &#123;return result;&#125;</span><br><span class="line">        /**</span><br><span class="line">         * 返回值为List集合时</span><br><span class="line">         */</span><br><span class="line">        if(result instanceof List) &#123;</span><br><span class="line">            List&lt;Object&gt; list = (List&lt;Object&gt;) result;</span><br><span class="line">            resourcePushService.push(list);</span><br><span class="line">        &#125;</span><br><span class="line">        /**</span><br><span class="line">         * 返回值为单值时，返回的实例类型必须继承BaseEntity</span><br><span class="line">         */</span><br><span class="line">        else if(result instanceof BaseEntity) &#123;</span><br><span class="line">            resourcePushService.push(result);</span><br><span class="line">        &#125;</span><br><span class="line">        logger.info(&quot;资源自动设置Aop切面逻辑处理完成.&quot;);</span><br><span class="line">        return result;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>切面环绕方法<code>resourcePutAround</code>大致流程为：</p>
<ol>
<li>执行需要切面的方法，获取方法结果</li>
<li>根据方法返回的结果判断是单个、多个对象进行调用不同的方法</li>
<li>统一资源方法自动根据<code>@ResourceField</code>注解配置信息以及对象类型配置<code>@Id</code>字段的值作为目标对象编号设置资源到返回对象内。</li>
<li>返回处理后的对象实例</li>
</ol>
<p>为了方便配置我们在<code>@ResourceField</code>注解内添加了<code>CommonResourceFlag</code>枚举类型的<code>flag</code>属性，该属性就是配置了资源类型的标识，切面会根据该标识去查询资源的类型编号，再拿着资源类型的编号 &amp; 目标编号去查询资源列表，<code>CommonResourceFlag</code>枚举代码如下所示：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 资源标识枚举</span><br><span class="line"> * ========================</span><br><span class="line"> * Created with IntelliJ IDEA.</span><br><span class="line"> * User：恒宇少年</span><br><span class="line"> * Date：2017/12/31</span><br><span class="line"> * Time：下午3:40</span><br><span class="line"> * 码云：http://git.oschina.net/jnyqy</span><br><span class="line"> * ========================</span><br><span class="line"> */</span><br><span class="line">@Getter</span><br><span class="line">public enum CommonResourceFlag</span><br><span class="line">&#123;</span><br><span class="line">    /**</span><br><span class="line">     * 用户头像</span><br><span class="line">     */</span><br><span class="line">    USER_HEAD_IMAGE(&quot;USER_HEAD_IMAGE&quot;),</span><br><span class="line">    /**</span><br><span class="line">     * 用户背景图片</span><br><span class="line">     */</span><br><span class="line">    USER_BACK_IMAGE(&quot;USER_BACK_IMAGE&quot;);</span><br><span class="line">    private String name;</span><br><span class="line"></span><br><span class="line">    CommonResourceFlag(String name) &#123;</span><br><span class="line">        this.name = name;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>以上我们简单介绍了<code>common-resource</code>子模块的核心内容以及基本的运行流程原理，下面我们来创建一个<code>user-provider</code>子模块来使用同一资源查询用户的头像、用户背景图片列表。</p>
<h3 id="user-provider"><a href="#user-provider" class="headerlink" title="user-provider"></a>user-provider</h3><p><code>user-provider</code>子模块目内我们预计添加一个查询用户详情的方法，在方法上配置<code>@ResourceMethod</code>注解，这样可以让切面切到该方法，然后在查询用户详情方法返回的对象类型内字段上添加<code>@ResourceField</code>注解并添加对应的资源类型标识配置，这样我们就可以实现资源的自动映射。</p>
<p>由于该模块需要数据库的支持，在<code>application.yml</code>配置文件内添加对应的数据库链接配置信息，如下所示：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">#数据源配置</span><br><span class="line">spring:</span><br><span class="line">  jpa:</span><br><span class="line">    properties:</span><br><span class="line">      hibernate:</span><br><span class="line">        show_sql: true</span><br><span class="line">        format_sql: true</span><br><span class="line">  datasource:</span><br><span class="line">    druid:</span><br><span class="line">      driver-class-name: com.mysql.jdbc.Driver</span><br><span class="line">      username: root</span><br><span class="line">      password: 123456</span><br><span class="line">      url: jdbc:mysql://127.0.0.1:3306/resources?characterEncoding=utf8</span><br></pre></td></tr></table></figure></p>
<p>配置文件内使用的<code>druid</code>是<code>alibaba</code>针对<code>SpringBoot</code>封装的<code>jar</code>，提供了<code>yml</code>配置文件相关支持以及提示。</p>
<h4 id="用户实体构建"><a href="#用户实体构建" class="headerlink" title="用户实体构建"></a>用户实体构建</h4><p>针对数据库内的用户基本信息表我们需要创建对应的<code>Entity</code>实体，代码如下所示：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 用户基本信息实体</span><br><span class="line"> * @author yuqiyu</span><br><span class="line"> * ========================</span><br><span class="line"> * Created with IntelliJ IDEA.</span><br><span class="line"> * User：恒宇少年</span><br><span class="line"> * Date：2017/12/31</span><br><span class="line"> * Time：上午11:18</span><br><span class="line"> * 码云：http://git.oschina.net/jnyqy</span><br><span class="line"> * ========================</span><br><span class="line"> */</span><br><span class="line">@Data</span><br><span class="line">@Entity</span><br><span class="line">@Table(name = &quot;hy_user_info&quot;)</span><br><span class="line">public class UserInfoEntity</span><br><span class="line">    extends BaseEntity</span><br><span class="line">&#123;</span><br><span class="line">    /**</span><br><span class="line">     * 用户编号</span><br><span class="line">     */</span><br><span class="line">    @Id</span><br><span class="line">    @GeneratedValue(generator = &quot;system-uuid&quot;)</span><br><span class="line">    @GenericGenerator(name = &quot;system-uuid&quot;, strategy = &quot;uuid&quot;)</span><br><span class="line">    @Column(name = &quot;UI_ID&quot;)</span><br><span class="line">    private String userId;</span><br><span class="line">    /**</span><br><span class="line">     * 用户名</span><br><span class="line">     */</span><br><span class="line">    @Column(name = &quot;UI_NAME&quot;)</span><br><span class="line">    private String userName;</span><br><span class="line">    /**</span><br><span class="line">     * 昵称</span><br><span class="line">     */</span><br><span class="line">    @Column(name = &quot;UI_NICK_NAME&quot;)</span><br><span class="line">    private String nickName;</span><br><span class="line">    /**</span><br><span class="line">     * 年龄</span><br><span class="line">     */</span><br><span class="line">    @Column(name = &quot;UI_AGE&quot;)</span><br><span class="line">    private int age;</span><br><span class="line">    /**</span><br><span class="line">     * 所居地</span><br><span class="line">     */</span><br><span class="line">    @Column(name = &quot;UI_ADDRESS&quot;)</span><br><span class="line">    private String address;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>由于我们的用户头像以及用户背景图片并没有在<code>用户基本信息表</code>内所以我们需要单独创建一个用户详情实体并继承用户基本信息实体，如下所示：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 用户详情dto映射实体</span><br><span class="line"> * @author yuqiyu</span><br><span class="line"> * ========================</span><br><span class="line"> * Created with IntelliJ IDEA.</span><br><span class="line"> * User：恒宇少年</span><br><span class="line"> * Date：2017/12/31</span><br><span class="line"> * Time：上午11:54</span><br><span class="line"> * 码云：http://git.oschina.net/jnyqy</span><br><span class="line"> * ========================</span><br><span class="line"> */</span><br><span class="line">@Data</span><br><span class="line">public class UserDetailDTO</span><br><span class="line">    extends UserInfoEntity</span><br><span class="line">&#123;</span><br><span class="line">    /**</span><br><span class="line">     * 用户头像</span><br><span class="line">     */</span><br><span class="line">    @ResourceField(flag = CommonResourceFlag.USER_HEAD_IMAGE)</span><br><span class="line">    private String headImage;</span><br><span class="line">    /**</span><br><span class="line">     * 背景图片</span><br><span class="line">     */</span><br><span class="line">    @ResourceField(flag = CommonResourceFlag.USER_BACK_IMAGE,multiple = true)</span><br><span class="line">    private List&lt;String&gt; backImage;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>在上面实体内我们仅仅是配置了字段所需的资源类型枚举。</p>
<blockquote>
<p>我们一般在开发过程中，用户表内对应的实体是不允许根据业务逻辑修改的，如果你需要变动需要继承实体后添加对应的字段即可。</p>
</blockquote>
<ul>
<li><p>用户数据接口</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 用户基本信息数据接口</span><br><span class="line"> * @author yuqiyu</span><br><span class="line"> * ========================</span><br><span class="line"> * Created with IntelliJ IDEA.</span><br><span class="line"> * User：恒宇少年</span><br><span class="line"> * Date：2017/12/31</span><br><span class="line"> * Time：上午11:30</span><br><span class="line"> * 码云：http://git.oschina.net/jnyqy</span><br><span class="line"> * ========================</span><br><span class="line"> */</span><br><span class="line">public interface UserInfoRepository</span><br><span class="line">    extends JpaRepository&lt;UserInfoEntity,String&gt;</span><br><span class="line">&#123;</span><br><span class="line">    /**</span><br><span class="line">     * 根据用户名称查询</span><br><span class="line">     * @param userName</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    UserInfoEntity findUserInfoEntityByUserName(String userName);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>用户业务逻辑实现</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 用户基本信息业务逻辑实现</span><br><span class="line"> *</span><br><span class="line"> * @author yuqiyu</span><br><span class="line"> * ========================</span><br><span class="line"> * Created with IntelliJ IDEA.</span><br><span class="line"> * User：恒宇少年</span><br><span class="line"> * Date：2017/12/31</span><br><span class="line"> * Time：上午11:53</span><br><span class="line"> * 码云：http://git.oschina.net/jnyqy</span><br><span class="line"> * ========================</span><br><span class="line"> */</span><br><span class="line">@Service</span><br><span class="line">@Transactional(rollbackFor = Exception.class)</span><br><span class="line">public class UserInfoService &#123;</span><br><span class="line">    /**</span><br><span class="line">     * 用户数据接口</span><br><span class="line">     */</span><br><span class="line">    @Autowired</span><br><span class="line">    private UserInfoRepository userInfoRepository;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 更新用户名称查询用户详情</span><br><span class="line">     * @param userName 用户名</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    @ResourceMethod</span><br><span class="line">    public UserDetailDTO selectByUserName(String userName) &#123;</span><br><span class="line">        /**</span><br><span class="line">         * 获取用户基本信息</span><br><span class="line">         */</span><br><span class="line">        UserInfoEntity userInfoEntity = userInfoRepository.findUserInfoEntityByUserName(userName);</span><br><span class="line">        /**</span><br><span class="line">         * 通过mapStruct转换detailDto</span><br><span class="line">         */</span><br><span class="line">        UserDetailDTO detailDTO = UserMapStruct.INSTANCE.fromUserEntity(userInfoEntity);</span><br><span class="line">        return detailDTO;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>我们在方法<code>selectByUserName</code>上配置了<code>@ResourceMethod</code>，让统一资源可以切面到该方法上，在<code>selectByUserName</code>方法内我们只需要去处理根据用户名查询的业务逻辑，通过<code>MapStruct</code>进行<code>UserInfoEntity</code>与<code>UserDetailDTO</code>转换。在方法返回对象时就会被资源自动处理分别将查询到的资源设置到<code>UserDetailDTO</code>内的<code>headImage</code>、<code>backImage</code>。</p>
<ul>
<li>用户控制器<br>我们在控制器内添加一个根据用户名查询用户详情的方法，如下所示：<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * ========================</span><br><span class="line"> * Created with IntelliJ IDEA.</span><br><span class="line"> * User：恒宇少年</span><br><span class="line"> * Date：2017/12/31</span><br><span class="line"> * Time：下午3:09</span><br><span class="line"> * 码云：http://git.oschina.net/jnyqy</span><br><span class="line"> * ========================</span><br><span class="line"> */</span><br><span class="line">@RestController</span><br><span class="line">@RequestMapping(value = &quot;/user&quot;)</span><br><span class="line">public class UserInfoController</span><br><span class="line">&#123;</span><br><span class="line">    /**</span><br><span class="line">     * 用户基本信息业务逻辑实现</span><br><span class="line">     */</span><br><span class="line">    @Autowired</span><br><span class="line">    private UserInfoService userInfoService;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 根据用户名查询详情</span><br><span class="line">     * @param userName 用户名</span><br><span class="line">     * @return</span><br><span class="line">     */</span><br><span class="line">    @RequestMapping(value = &quot;/&#123;userName&#125;&quot;,method = RequestMethod.GET)</span><br><span class="line">    public UserDetailDTO detail(@PathVariable(&quot;userName&quot;) String userName)</span><br><span class="line">    &#123;</span><br><span class="line">        return userInfoService.selectByUserName(userName);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>下面我们来编写一个测试用例，查看是否能够达到我们预计的效果。</p>
<h1 id="测试"><a href="#测试" class="headerlink" title="测试"></a>测试</h1><p>我们在<code>src/test</code>下创建一个名为<code>CommonResourceTester</code>测试类，代码如下所示：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 测试用例</span><br><span class="line"> * ========================</span><br><span class="line"> * Created with IntelliJ IDEA.</span><br><span class="line"> * User：恒宇少年</span><br><span class="line"> * Date：2017/12/31</span><br><span class="line"> * Time：下午5:04</span><br><span class="line"> * 码云：http://git.oschina.net/jnyqy</span><br><span class="line"> * ========================</span><br><span class="line"> */</span><br><span class="line">@SpringBootTest(classes = Chapter44Application.class)</span><br><span class="line">@RunWith(SpringRunner.class)</span><br><span class="line">public class CommonResourceTester</span><br><span class="line">&#123;</span><br><span class="line">    /**</span><br><span class="line">     * 模拟mvc测试对象</span><br><span class="line">     */</span><br><span class="line">    private MockMvc mockMvc;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * web项目上下文</span><br><span class="line">     */</span><br><span class="line">    @Autowired</span><br><span class="line">    private WebApplicationContext webApplicationContext;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 所有测试方法执行之前执行该方法</span><br><span class="line">     */</span><br><span class="line">    @Before</span><br><span class="line">    public void before() &#123;</span><br><span class="line">        //获取mockmvc对象实例</span><br><span class="line">        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 测试查询用户详情</span><br><span class="line">     * @throws Exception</span><br><span class="line">     */</span><br><span class="line">    @Test</span><br><span class="line">    public void selectDetail() throws Exception</span><br><span class="line">    &#123;</span><br><span class="line">        /**</span><br><span class="line">         * 发起获取请求</span><br><span class="line">         */</span><br><span class="line">        MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get(&quot;/user/hengboy&quot;))</span><br><span class="line">        .andDo(MockMvcResultHandlers.log())</span><br><span class="line">        .andReturn();</span><br><span class="line"></span><br><span class="line">        int status = mvcResult.getResponse().getStatus();</span><br><span class="line"></span><br><span class="line">        mvcResult.getResponse().setCharacterEncoding(&quot;UTF-8&quot;);</span><br><span class="line">        String responseString = mvcResult.getResponse().getContentAsString();</span><br><span class="line"></span><br><span class="line">        Assert.assertEquals(&quot;请求错误&quot;, 200, status);</span><br><span class="line"></span><br><span class="line">        System.out.println(responseString);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>接下来我们执行<code>selectDetail</code>测试方法，看下控制台输出对应的  <code>JSON</code>内容，格式化后如下所示：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    &quot;userId&quot;: &quot;bc4c8e38-edd6-11e7-969c-3c15c2e4a8a6&quot;, </span><br><span class="line">    &quot;userName&quot;: &quot;hengboy&quot;, </span><br><span class="line">    &quot;nickName&quot;: &quot;恒宇少年&quot;, </span><br><span class="line">    &quot;age&quot;: 23, </span><br><span class="line">    &quot;address&quot;: &quot;山东省济南市&quot;, </span><br><span class="line">    &quot;headImage&quot;: &quot;https://upload.jianshu.io/users/upload_avatars/4461954/f09ba256-f6db-41ed-a4ac-b2d23737f0ac.jpg?imageMogr2/auto-orient/strip|imageView2/1/w/96/h/96&quot;, </span><br><span class="line">    &quot;backImage&quot;: [</span><br><span class="line">        &quot;https://upload.jianshu.io/collections/images/358868/android.graphics.Bitmap_d88b4de.jpeg?imageMogr2/auto-orient/strip|imageView2/1/w/240/h/240&quot;, </span><br><span class="line">        &quot;https://upload.jianshu.io/collections/images/522928/kafka_diagram.png?imageMogr2/auto-orient/strip|imageView2/1/w/240/h/240&quot;</span><br><span class="line">    ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>根据结果我们可以看到，我们已经自动的读取了配置的资源列表，也通过反射自动设置到字段内。</p>
<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><p>本章的代码比较多，还是建议大家根据源码比对学习，这种方式也是我们在平时开发中总结出来的，我们仅仅需要配置下<code>@ResourceField</code>以及<code>@ResourceMethod</code>就可以了完成资源的自动映射，资源与业务逻辑的耦合度得到的很好的降低。</p>
<p>本章源码已经上传到码云：<br>SpringBoot配套源码地址：<a href="https://gitee.com/hengboy/spring-boot-chapter" target="_blank" rel="noopener">https://gitee.com/hengboy/spring-boot-chapter</a><br>SpringCloud配套源码地址：<a href="https://gitee.com/hengboy/spring-cloud-chapter" target="_blank" rel="noopener">https://gitee.com/hengboy/spring-cloud-chapter</a><br>SpringBoot相关系列文章请访问：<a href="http://www.jianshu.com/p/9a08417e4e84" target="_blank" rel="noopener">目录：SpringBoot学习目录</a><br>QueryDSL相关系列文章请访问：<a href="http://www.jianshu.com/p/99a5ec5c3bd5" target="_blank" rel="noopener">QueryDSL通用查询框架学习目录</a><br>SpringDataJPA相关系列文章请访问：<a href="http://www.jianshu.com/p/615ed9c1fe84" target="_blank" rel="noopener">目录：SpringDataJPA学习目录</a>，感谢阅读！<br>欢迎加入QQ技术交流群，共同进步。<br><img src="http://upload-images.jianshu.io/upload_images/4461954-d80b777ca38632ba.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="QQ技术交流群"></p>

        
        </div>
        <footer class="article-footer">
            <div class="share-container">


    <div class="bdsharebuttonbox">
    <a href="#" class="bds_more" data-cmd="more">分享到：</a>
    <a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间">QQ空间</a>
    <a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博">新浪微博</a>
    <a href="#" class="bds_tqq" data-cmd="tqq" title="分享到腾讯微博">腾讯微博</a>
    <a href="#" class="bds_renren" data-cmd="renren" title="分享到人人网">人人网</a>
    <a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信">微信</a>
</div>
<script>
window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{"bdSize":16}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
</script>
<style>
    .bdshare_popup_box {
        border-radius: 4px;
        border: #e1e1e1 solid 1px;
    }
    .bdshare-button-style0-16 a,
    .bdshare-button-style0-16 .bds_more {
        padding-left: 20px;
        margin: 6px 10px 6px 0;
    }
    .bdshare_dialog_list a,
    .bdshare_popup_list a,
    .bdshare_popup_bottom a {
        font-family: 'Microsoft Yahei';
    }
    .bdshare_popup_top {
        display: none;
    }
    .bdshare_popup_bottom {
        height: auto;
        padding: 5px;
    }
</style>


</div>

            
    

        </footer>
    </div>
    
        
<nav id="article-nav">
    
        <a href="/spring-boot-chapter-45/" id="article-nav-newer" class="article-nav-link-wrap">
            <strong class="article-nav-caption">上一篇</strong>
            <div class="article-nav-title">
                
                    第四十五章：基于SpringBoot 设计业务逻辑异常统一处理
                
            </div>
        </a>
    
    
        <a href="/spring-boot-chapter-43/" id="article-nav-older" class="article-nav-link-wrap">
            <strong class="article-nav-caption">下一篇</strong>
            <div class="article-nav-title">第四十三章： 基于SpringBoot &amp; RabbitMQ完成TopicExchange分布式消息消费</div>
        </a>
    
</nav>


    
</article>


    
    

</section>
            
			
				
<aside id="sidebar">
   
        
    <div class="widget-wrap">
        <h3 class="widget-title">最新文章</h3>
        <div class="widget">
            <ul id="recent-post" class="no-thumbnail">
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a></p>
                            <p class="item-title"><a href="/spring-boot-chapter-52/" class="title">第五十二章：基于SpringBoot2使用Rest访问MongoDB数据</a></p>
                            <p class="item-date"><time datetime="2018-04-21T16:00:00.000Z" itemprop="datePublished">2018-04-22</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a></p>
                            <p class="item-title"><a href="/spring-boot-chapter-51/" class="title">第五十一章：基于SpringBoot2 &amp; MongoDB完成自动化集成</a></p>
                            <p class="item-date"><time datetime="2018-04-15T16:00:00.000Z" itemprop="datePublished">2018-04-16</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a></p>
                            <p class="item-title"><a href="/spring-boot-chapter-50/" class="title">第五十章：SpringBoot2.0新特性 - 岂止至今最简单redis缓存集成</a></p>
                            <p class="item-date"><time datetime="2018-04-14T16:00:00.000Z" itemprop="datePublished">2018-04-15</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a></p>
                            <p class="item-title"><a href="/spring-boot-chapter-49/" class="title">第四十九章：SpringBoot2.0新特性 - 你get到WebMvcConfigurer两种配置方式了吗？</a></p>
                            <p class="item-date"><time datetime="2018-03-16T16:00:00.000Z" itemprop="datePublished">2018-03-17</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a></p>
                            <p class="item-title"><a href="/spring-boot-chapter-48/" class="title">第四十八章：SpringBoot2.0新特性 - RabbitMQ信任package设置</a></p>
                            <p class="item-date"><time datetime="2018-03-12T16:00:00.000Z" itemprop="datePublished">2018-03-13</time></p>
                        </div>
                    </li>
                
            </ul>
        </div>
    </div>

    
        
    <div class="widget-wrap">
        <h3 class="widget-title">分类</h3>
        <div class="widget">
            <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/QueryDSL-核心技术/">QueryDSL 核心技术</a><span class="category-list-count">7</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a><span class="category-list-count">36</span></li></ul>
        </div>
    </div>

    
        
    <div class="widget-wrap">
        <h3 class="widget-title">归档</h3>
        <div class="widget">
            <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/04/">四月 2018</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/03/">三月 2018</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/01/">一月 2018</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/12/">十二月 2017</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/11/">十一月 2017</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/10/">十月 2017</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/09/">九月 2017</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/08/">八月 2017</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/07/">七月 2017</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/06/">六月 2017</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/05/">五月 2017</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/04/">四月 2017</a><span class="archive-list-count">5</span></li></ul>
        </div>
    </div>

    
        
    <div class="widget-wrap">
        <h3 class="widget-title">标签</h3>
        <div class="widget">
            <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/QueryDSL/">QueryDSL</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/SpringBoot/">SpringBoot</a><span class="tag-list-count">43</span></li></ul>
        </div>
    </div>

    
        
    <div class="widget-wrap">
        <h3 class="widget-title">标签云</h3>
        <div class="widget tagcloud">
            <a href="/tags/QueryDSL/" style="font-size: 10px;">QueryDSL</a> <a href="/tags/SpringBoot/" style="font-size: 20px;">SpringBoot</a>
        </div>
    </div>

    
        
    <div class="widget-wrap widget-list">
        <h3 class="widget-title">链接</h3>
        <div class="widget">
            <ul>
                
                    <li>
     				<a href="http://hexo.io" target="_blank">Hexo</a>
					</li>
                
            </ul>
        </div>
    </div>


    
    <div id="toTop" class="fa fa-angle-up"></div>
</aside>

				
        </div>
        <!--引入不蒜子-->
<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<footer id="footer">
    <div class="outer">
        <div id="footer-info" class="inner">
            <span  id="busuanzi_container_site_pv">本站总访问量<span id="busuanzi_value_site_pv"></span>次</span>
            &copy; 2017 - 2018 恒宇少年 - 版权所有<br>
        </div>
    </div>
</footer>

        


    
        <script src="/libs/lightgallery/js/lightgallery.min.js"></script>
        <script src="/libs/lightgallery/js/lg-thumbnail.min.js"></script>
        <script src="/libs/lightgallery/js/lg-pager.min.js"></script>
        <script src="/libs/lightgallery/js/lg-autoplay.min.js"></script>
        <script src="/libs/lightgallery/js/lg-fullscreen.min.js"></script>
        <script src="/libs/lightgallery/js/lg-zoom.min.js"></script>
        <script src="/libs/lightgallery/js/lg-hash.min.js"></script>
        <script src="/libs/lightgallery/js/lg-share.min.js"></script>
        <script src="/libs/lightgallery/js/lg-video.min.js"></script>
    
    
        <script src="/libs/justified-gallery/jquery.justifiedGallery.min.js"></script>
    
    



<!-- Custom Scripts -->
<script src="/js/main.js"></script>

    </div>
</body>
</html>